<?
    var pageNumber = page.pageNumber;   // 当前页
    var totalPage = page.totalPage;     // 总页数
    var num_display_entries = 10;       // 每次显示多少页
    var num_edge_entries = 2;           // 前后各多少页
    var ellipse_text = "...";
    var uri = action+"/";
    if (page.totalRow > page.pageSize) {
?>
<ul class="pagination pagination-group">
<?
        // 上一页
        if(pageNumber != 1) { 
            printf("<li><a href=\"%s%s\">上一页</a></li>",uri,pageNumber-1);
        } else {
            printf("<li class=\"disabled\"><a href=\"\">上一页</a><li>");
        }
        // 总页数大于 (显示的页数+前后显示) 表示需要显示很多页
        var pageCount = totalPage - (num_display_entries + num_edge_entries * 2);
        if (pageCount > 0) {
            var i = 1;
            var len = 0;
            var _start = trunc(num_display_entries / 2);
            var _end = _start;
            if (num_display_entries%2 == 0) {
                _start = _start - 1;
            }
            // 页码-前
            if (pageNumber - _start - num_edge_entries >= num_edge_entries) {
                while(i < num_edge_entries + 1) {
                    printf("<a href='%s%s'>%s</a> ",uri,i,i);
                    i = i + 1;
                }
                printf("<span>%s</span> ",ellipse_text);
                 
                i = pageNumber-_start;
                len = pageNumber + _end+1;
            } else {
                len = num_display_entries+1;
            }
     
            var show_num_edge_entries_next = totalPage - pageNumber - _end - num_edge_entries > 0;
            if (!show_num_edge_entries_next) {
                i = pageNumber - _start;
                if (totalPage - pageNumber - _end < 0) {
                    i = totalPage - num_display_entries+1;
                }
                len = totalPage + 1;
            }
             
            // 显示中间的那串页码
            while(i < len) {
                if (pageNumber == i) {
                    printf("<li class=\"active\"><a href=''>%s</a></li>",i);
                } else {
                    printf("<li><a href='%s%s'>%s</a></li>",uri,i,i);
                }
                i = i + 1;
            }
             
            // 页码-后
            if (show_num_edge_entries_next) {
                printf("<span>%s</span> ",ellipse_text);
                i = totalPage + 1 - num_edge_entries;
                while(i < totalPage + 1) {
                    printf("<a href='%s%s'>%s</a> ",uri,i,i);
                    i = i + 1;
                }
            }
        } else {
            // 显示全部页码
            var i = 1;
            while(i < totalPage + 1) {
                if (pageNumber == i) {
                    printf("<li class=\"active\"><a href=''>%s</a></li>",i);
                } else {
                    printf("<li><a href='%s%s'>%s</a></li>",uri,i,i);
                }
                i = i + 1;
            }
        }
 
    // 下一页
        if(pageNumber != totalPage) {
            printf("<li><a href=\"%s%s\">下一页</a></li>",uri,pageNumber+1);
        } else {
            printf("<li class=\"disabled\"><a href=\"\">下一页</a></li>");
        }
    }
?>
</ul>